public class Singletontest04 {
    static {
        System.out.println("饿汉式-线程安全-同步方法!");
    }

    public static void main(String[] args) throws Exception{
        Singletion04 instance =  Singletion04.getInstance();
        Singletion04 instance2 = Singletion04.getInstance();
        System.out.println(instance == instance2);
        System.out.println(instance.hashCode());
        System.out.println(instance2.hashCode());
    }
}
class Singletion04{
    private Singletion04(){}
    private static Singletion04 instance;
    public static synchronized Singletion04 getInstance(){
        if (instance==null){
            instance=new Singletion04();
        }
        return instance;
    }
}
